﻿<UserControl x:Class="FormCreator.View.FormDesigner"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:wpf="clr-namespace:FormCreator.Wpf"
             xmlns:e="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="600">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" MinWidth="300"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        
        <!-- Column 0: Editor and buttons -->
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock Margin="10 20 20 20" FontWeight="Bold" FontSize="14" Text="Form structure"/>
            <TreeView Grid.Row="1" Grid.Column="0" Margin="10" ItemsSource="{Binding Sections}" BorderThickness="0" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}" dd:DragDrop.IsDragSource="True">
                <TreeView.Resources>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
                    </Style>
                </TreeView.Resources>
                <e:Interaction.Behaviors>
                    <wpf:BindableSelectedItemBehavior SelectedItem="{Binding SelectedElement, Mode=OneWayToSource}" />
                </e:Interaction.Behaviors>
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Path=Children}">
                        <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" />
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
            </TreeView>
            <UniformGrid Grid.Row="3" Rows="1">
                <Button Content="Load" Command="{Binding LoadCommand}"/>
                <Button Content="Save" Command="{Binding SaveCommand}"/>
            </UniformGrid>
        </Grid>
        
        <!-- Column 1: Properties-->
        <StackPanel Grid.Column="1">
            <TextBlock Margin="0 20 20 20" FontWeight="Bold" FontSize="14" Text="Properties"/>
            <StackPanel Margin="20 0 0 0">
                <TextBlock FontWeight="Bold" Text="Form"/>
                <ContentControl Content="{Binding FormProperties}"/>
                <TextBlock FontWeight="Bold" Text="Selected element"/>
                <ContentControl Content="{Binding Properties}"/>
                <Button Margin="20" Content="Delete selected element" Command="{Binding DeleteElementCommand}"/>
            </StackPanel>
        </StackPanel>
    </Grid>
    
</UserControl>
